$(function(){
	$("#customer_mana_datagrid").datagrid({    
	    url:'admin/system/customer_manage?method=index', 
	    loadMsg:'数据加载中···',
	    toolbar:'#toolb',
	    fit:'true',
	    idField:'id',
	    pagination:true,
	    rownumbers:true,//行号  
	    checkOnSelect : true,
		selectOnCheck : true,
		collapsible: true,
	    columns:[[
	    {
			field : "ck",
			checkbox : true
		}, {
			field : "id",
			hidden : true
		},     
	    {
			field:'customerNo',
			title:'客户编号',
			width:120,
			align:'center'
	    },    
	    {
	    	field:'user_name',
	    	title:'客户姓名',
	    	width:120,
	    	align:'center'
	     },
	     {
	    	 field:'login_name',
	    	 title:'登录名',
	    	 width:120,
	    	 align:'center'
	    },
	     {
	    	 field:'user_mobile',
	    	 title:'手机',
	    	 width:120,
	    	 align:'center'
	    },
	     {
	    	 field:'alipayNo',
	    	 title:'支付宝号',
	    	 width:180,
	    	 align:'center'
	    },
	     {
	    	 field:'transaction',
	    	 title:'主要业务',
	    	 width:120,
	    	 align:'center'
	    }
	    ,
//	     {
//	    	 field:'qqNumber',
//	    	 title:'QQ',
//	    	 width:100,
//	    	 align:'center'
//	    },
	     {
	    	 field:'companyName',
	    	 title:'公司名称',
	    	 width:200,
	    	 align:'center'
	    },
	     {
	    	 field:'companyPhone',
	    	 title:'公司电话',
	    	 width:120,
	    	 align:'center'
	    },
	    {
	    	field:'update',
	    	title:'详情及修改',
	    	width:100,
	    	align:'center',
	    	 formatter:function(value, row, index){
	    		 var action = '<a href="javascript:void(0)" onclick="operatorCustom(this)" class="operator-btn">点击修改查看</a>';
	    		 return action;
	    	 }
	    }
//	    ,
//	     {
//	    	 field:'companyAddr',
//	    	 title:'公司地址',
//	    	 width:80,
//	    	 align:'center',
//	    	 formatter: function(value,row,index){
//	   	        	return "<a href='javascript:void(0)' onclick=\"showAddress('"+row['companyAddr']+"')\">查看</a>";
//	   	     }
//	    }
	    ]],
	    fitColumns:true
	});  	
});
function showAddress(address){
	if(address==undefined || address==null){
		$.messager.alert('地址信息','未填写！');
	}else{
		$.messager.alert('地址信息',address);
	}
}

function doSearch(){
    $('#customer_mana_datagrid').datagrid('load', {  
    	customerNo: $('#search_cust_no').val(),  
    	user_name: $('#search_cust_name').val()  
    });  
}

function operatorCustom(target){
	var rows = $("#customer_mana_datagrid").datagrid('getRows');
	var row = rows[getRowIndex(target)];
	var id = row.id;
	var resObj=$.ajax({url:'admin/system/customer_manage?method=show&id='+id,async:false}).responseJSON;
	console.log(resObj);
	$("#update_customer_form").form('load',resObj);
	$("#update_info_modal").window('open');
}



function getRowIndex(target){
	var tr = $(target).closest('tr.datagrid-row');
	return parseInt(tr.attr('datagrid-row-index'));
}

function doDelete(){
	var ids = [];
	var rows = $("#customer_mana_datagrid").datagrid('getSelections');
	if(rows==null||rows.length==0)
		$.messager.alert('提示信息','请选中数据删除!');
	else {
		$.messager.confirm('确认消息', '确定删除吗?', function(r){
			if (r){

				for(var i = 0;i<rows.length;i++)
					ids.push(rows[i].id);
				$.ajax({
					type:'POST',
					dataType:'json',
					url:'admin/system/customer_manage?method=delete',
					data:{"ids": ids }, 
					traditional:true,
					success:function(data){
						$.messager.alert('提示信息',data.msg);
						if(data.success){
							$('#customer_mana_datagrid').datagrid('load');
							$('#customer_mana_datagrid').datagrid("clearSelections")
						}
					}
				});
			}
		});
	}
}
/**密码重置*/
function resetPass(){
	var ids = [];
	var rows = $("#customer_mana_datagrid").datagrid('getSelections');
	if(rows==null||rows.length==0)
		$.messager.alert('提示信息','请选一条客户记录!');
	else {
		$.messager.confirm('确认消息', '确定重置密码?', function(r){
			if (r){

				for(var i = 0;i<rows.length;i++)
					ids.push(rows[i].id);
				$.ajax({
					type:'POST',
					dataType:'json',
					url:'admin/system/resetPass.do',
					data:{"ids": ids }, 
					traditional:true,
					success:function(data){
						$.messager.alert('提示信息',data.msg);
						if(data.success){
							$('#customer_mana_datagrid').datagrid('load');
							$('#customer_mana_datagrid').datagrid("clearSelections")
						}
					}
				});
			}
		});
	}
}